package com.buba.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.buba.feign.staffFeign;
import com.buba.mapper.PayrollsMapper;
import com.buba.service.PayrollsService;
import entity.salary.Payrolls;
import entity.salary.vo.selPeopleSalaryInformationVo;
import entity.staff.Accounting;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import utils.PageResult;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author beisheng
 * @since 2023-03-31
 */
@Service
public class PayrollsServiceImpl extends ServiceImpl<PayrollsMapper, Payrolls> implements PayrollsService {

    @Resource
    private PayrollsMapper payrollsMapper;

    @Resource
    private staffFeign staffFeign;
    /* *
     * @Author: beisheng
     * @Descriprion: 分页查询工资单详情
     * @Date: 2023/3/31 13:55
     * @Return: common.R
     * @Param: [pageSize, pageNum]
     */

    @Override
    public PageResult selAllPayrolls(Integer pageSize, Integer pageNum) {
        List<selPeopleSalaryInformationVo> salaryInformationVos = new ArrayList<>();
        Page<Payrolls> payrollsPage = new Page<>(pageSize,pageNum);
        Page<Payrolls> payrollsPages = payrollsMapper.selectPage(payrollsPage, new QueryWrapper<Payrolls>().eq("delete_flag", 0));
        List<Payrolls> payrollsList = payrollsMapper.selectList(new QueryWrapper<Payrolls>().eq("delete_flag", 0));
        for (Payrolls record : payrollsPages.getRecords()) {
            selPeopleSalaryInformationVo selPeopleSalaryInformationVo = new selPeopleSalaryInformationVo();
            BeanUtils.copyProperties(record,selPeopleSalaryInformationVo);
            Accounting accounting = staffFeign.selAccById(record.getAccId());
            BeanUtils.copyProperties(accounting,selPeopleSalaryInformationVo);
            salaryInformationVos.add(selPeopleSalaryInformationVo);
        }
        return new PageResult(pageSize,pageNum,payrollsList.size(),salaryInformationVos);
    }
}
